export const createBar = (name, x_data, y_data, topColor, bottomColor) => {
  return {
    tooltip: {
      trigger: 'axis',
      formatter: function (params, ticket, callback) {
        var res = ''
        for (var i = 0, l = params.length; i < l; i++) {
          res += '' + params[i].seriesName + ' : ' + params[i].value + '<br>'
        }
        return res
      },
      backgroundColor: '#0A1326',
      borderColor: '#535b69',
      borderRadius: 8,
      borderWidth: 2,
      padding: [5, 10],
      textStyle: {
        color: '#fff',
      },
    },
    legend: {
      icon: 'circle',
      itemWidth: 8,
      itemHeight: 8,
      itemGap: 10,
      data: [name],
      textStyle: {
        fontSize: 14,
        color: '#DADBDE',
      },
    },
    grid: {
      top: 30,
      right: 0,
      bottom: 30,
    },
    xAxis: {
      type: 'category',
      data: x_data,
      axisTick: {
        show: false,
      },
      axisLabel: {
        interval: 0,
        // rotate:50,
        show: true,
        splitNumber: 15,
        textStyle: {
          color: 'rgba(255,255,255,.6)',
          fontSize: '12',
        },
      },
    },
    yAxis: [
      {
        type: 'value',
        axisLabel: {
          //formatter: '{value} %'
          show: true,
          textStyle: {
            color: 'rgba(255,255,255,.6)',
            fontSize: '12',
          },
        },
        axisTick: {
          show: false,
        },
        splitLine: {
          lineStyle: {
            color: 'rgba(255,255,255,.1)',
            type: 'dashed',
          },
        },
      },
    ],
    series: [
      {
        name: name,
        type: 'bar',
        data: y_data,
        barWidth: '25%', //柱子宽度
        itemStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: topColor, // 顶部颜色
              },
              {
                offset: 1,
                color: bottomColor, // 底部颜色
              },
            ],
          },
          opacity: 1,
        },
      },
    ],
  }
}
export const createLine = (name, x_data, y_data, topColor, bottomColor) => {
  return {
    tooltip: {
      trigger: 'axis',
      formatter: function (params, ticket, callback) {
        var res = ''
        for (var i = 0, l = params.length; i < l; i++) {
          res += '' + params[i].seriesName + ' : ' + params[i].value + '<br>'
        }
        return res
      },
      backgroundColor: '#0A1326',
      borderColor: '#535b69',
      borderRadius: 8,
      borderWidth: 2,
      padding: [5, 10],
      textStyle: {
        color: '#fff',
      },
    },
    legend: {
      icon: 'circle',
      itemWidth: 8,
      itemHeight: 8,
      itemGap: 10,
      data: [name],
      textStyle: {
        fontSize: 14,
        color: '#DADBDE',
      },
    },
    grid: {
      top: 30,
      right: 0,
      bottom: 30,
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: true, //坐标轴两边是否留白
        axisLine: {
          //坐标轴线
          show: true,
          lineStyle: {
            color: '#515151',
          },
        },
        axisTick: {
          //坐标轴刻度线
          show: false,
        },
        axisLabel: {
          // show: true,
          // rotate: 10,
          margin: 0,
          color: '#D9D9D9',
        },
        data: x_data,
        offset: 10,
      },
    ],
    yAxis: [
      {
        type: 'value',
        axisLine: {
          //坐标轴线
          show: false,
          lineStyle: {
            color: '#fff',
          },
        },
        lineStyle: {
          type: 'dashed',
        },
        splitLine: {
          //坐标轴分割线
          lineStyle: {
            type: 'dashed',
            color: '#2b3646',
          },
        },
      },
    ],
    series: [
      {
        name: name,
        type: 'line',
        showSymbol: true,
        symbolSize: 8,
        data: y_data,
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: topColor, // 顶部颜色
              },
              {
                offset: 1,
                color: bottomColor, // 底部透明
              },
            ],
          },
        },
        itemStyle: {
          color: topColor,
        },
      },
    ],
  }
}
